local skel = fk.CreateSkill {
  name = "lb_zero__chiren",
  tags = { Skill.Switch },
}

Fk:loadTranslationTable {
  ["lb_zero__chiren"] = "炽刃",
  [":lb_zero__chiren"] = "<b>转换技</b>，你使用牌指定其他角色为唯一目标后，若此牌，阳：不因〖炽刃〗获得；阴：因〖炽刃〗获得；你可摸两张牌并弃置两张牌，将此牌改为火【杀】。" ..
      "准备阶段，你摸一张牌并将〖炽刃〗转为阳。",
  [":lb_zero__chiren_yang"] = "<<b>转换技</b>，你使用牌指定其他角色为唯一目标后，若此牌，<font color='#E0DB2F'>阳：不因〖炽刃〗获得；</font>阴：因〖炽刃〗获得；你可摸两张牌并弃置两张牌，将此牌改为火【杀】。" ..
      "准备阶段，你摸一张牌并将〖炽刃〗转为阳。",
  [":lb_zero__chiren_yin"] = "<<b>转换技</b>，你使用牌指定其他角色为唯一目标后，若此牌，阳：不因〖炽刃〗获得；<font color='#E0DB2F'>阴：因〖炽刃〗获得；</font>你可摸两张牌并弃置两张牌，将此牌改为火【杀】。" ..
      "准备阶段，你摸一张牌并将〖炽刃〗转为阳。",
  ["#lb_zero__chiren"] = "炽刃：你可摸两张牌并弃置两张牌，将 %arg 改为火【杀】",

  ["@@lb_zero__chiren-inhand"] = "炽刃",

  ["$lb_zero__chiren1"] = "火焰，听从我！",
  ["$lb_zero__chiren2"] = "准备，燃烧！",
  ["$lb_zero__chiren3"] = "自由开火！",
  ["$lb_zero__chiren4"] = "整装待发。",
}

skel:addEffect(fk.TargetSpecified, {
  audio_index = { 1, 2, 3 },
  anim_type = "drawcard",
  --[[
  times = function (self, player)
    return player:usedSkillTimes(skel.name)
  end,
  --]]
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.to ~= player and data:isOnlyTarget(data.to) and data.card.name ~= "fire__slash" then
      local state = player:getSwitchSkillState(skel.name)
      return
          (state == fk.SwitchYin and data.extra_data and data.extra_data.lb_zero__chiren == player.id) or
          (state == fk.SwitchYang and not (data.extra_data and data.extra_data.lb_zero__chiren == player.id))
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, prompt = "#lb_zero__chiren:::" .. data.card:toLogString() })
  end,
  on_use = function(self, event, target, player, data)
    local num = 2
    player:drawCards(2, skel.name, "top", "@@lb_zero__chiren-inhand")
    if not player:isKongcheng() then
      player.room:askToDiscard(player, {
        min_num = num,
        max_num = num,
        skill_name = skel.name,
        include_equip = true,
        cancelable = false,
      })
    end
    data:changeCard("fire__slash")
  end,
})

skel:addEffect(fk.PreCardUse, {
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card:getMark("@@lb_zero__chiren-inhand") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.lb_zero__chiren = player.id
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  audio_index = { 4 },
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, skel.name, "top", "@@lb_zero__chiren-inhand")
    if player:getSwitchSkillState(skel.name) ~= fk.SwitchYang then
      player.room:setPlayerMark(
        player,
        MarkEnum.SwithSkillPreName .. skel.name,
        fk.SwitchYang
      )
      player:setSkillUseHistory(skel.name, player:usedSkillTimes(skel.name), Player.HistoryTurn) -- 仅刷新UI
    end
    --player.room:notifySkillInvoked(player, skel.name, "special")
    --player:broadcastSkillInvoke(skel.name, 4)
  end,
})

return skel
